package org.amse.ys.sndeditor.model.modules;

import org.amse.ys.sndeditor.model.IModule;
import org.amse.ys.sndeditor.model.IDrawer;
import org.amse.ys.sndeditor.model.ISoundFile;
import org.amse.ys.sndeditor.model.drawer.AndroidDrawer;

public class DebuggingModule implements IModule {

	private IDrawer myDrawer;
	private int myXSize;
	private int myYSize;
	private int myCounter;
	private final String[] MENU_ITEMS = { "filename", "item 2", "item 3",
			"item 4", "item 5" };
	private ISoundFile mySoundFile;
	{
		myDrawer = AndroidDrawer.getDrawer();
	}

	private void sysOut(String text) {
		myDrawer.setColor(15, 0, 0, 0);
		myDrawer.drawRectangle(0, 0, myXSize, myYSize);
		myDrawer.setColor(255, 255, 255, 255);
		myDrawer.drawText(text, 20, ((myCounter++) % (myYSize / 20)) * 20);
	}

	public String getAppletName() {
		return "Debugging applet";
	}

	public String getMenuItemName(int numberOfItem) {

		return MENU_ITEMS[numberOfItem];
	}

	public int getNumberOfMenuOptions() {
		return MENU_ITEMS.length;
	}

	public void onTimer() {
		sysOut("onTimer");
	}

	public void refresh() {
		sysOut("refresh");
	}

	public void setSize(int width, int height) {
		myXSize = width;
		myYSize = height;
		myDrawer.setSize(width, height);
		sysOut("resize width=" + width + " height=" + height);
	}

	public IDrawer getDrawer() {
		sysOut("getDrawer");
		return myDrawer;
	}

	public int getEndPosition() {
		// TODO Auto-generated method stub
		return 0;
	}

	public int getStartPosition() {
		// TODO Auto-generated method stub
		return 0;
	}

	public int getTimerDelay() {
		return 1000;
	}

	public boolean isMagnifyable() {
		return false;
	}

	public boolean isScreenChanged() {
		return myDrawer.isChanged();
	}

	public boolean isSelectable() {
		return true;
	}

	public boolean isSelected() {
		// TODO Auto-generated method stub
		return false;
	}

	public boolean isSpinable(int posX, int posY, long time) {
		// TODO Auto-generated method stub
		return false;
	}

	public void onDPadKeyPressed() {
		sysOut("onDPad");

	}

	public void onMagnify(double timesToMagnify) {
		sysOut("onMagnify " + timesToMagnify);

	}

	public void onMenuItemSelected(int numberOfMenuOption) {
		if (numberOfMenuOption == 0) {
			sysOut(mySoundFile.isOpened() + "");
		}
		sysOut("Was selected option " + MENU_ITEMS[numberOfMenuOption]);

	}

	public void onSpin(double spin) {
		sysOut("onspin " + spin);

	}

	public void onTouch(int posX, int posY, long time) {
		sysOut("onTouch at position " + posX + ":" + posY + " - " + time);

	}

	// WARNING! this method should be extremely simple
	public void initilize(ISoundFile fileToProceed) {
		mySoundFile = fileToProceed;

	}

	public int getMenuItemIconIndex(int numberOfItem) {
		return -1;
	}

	@Override
	public ISoundFile getSoundFile() {
		// TODO Auto-generated method stub
		return null;
	}

}
